/**
 * role-edit.js
 */

define('user-edit',['jquery','base','liger.messageBox','liger.dialog','liger.all'],function(require, exports, module){
	var Base = require("base");
	var $ = require("jquery");
	require("liger.all")($);
	var ctx = Base.common.utils.getContextPath();
	
	var dialog = frameElement.dialog;
	
	var btns = [{text:'保存', 
   		click : function() {
			var form = liger.get("form");
			var data = form.getData();
			var param = {data:liger.toJSON(data)};
	        $.ajax({
	    		url: ctx+ '/usr/save.do',
	    		type : 'POST', 
	    		dataType : 'json',
	    		data : param,
	    		success : function(backData) {
	    			if(backData){
	    				window.parent.jQuery("#dataGrid").ligerGetGridManager().reload();
	    			}}});
        }},{text:'取消',
        		click : function() {
        			 dialog.close();
        		}
            }];

	
	var $form = $("#form").ligerForm({
        inputWidth: 170, labelWidth: 90, space: 40,
         fields: [
         { name: "id", type: "hidden" },
         { display: "用户名称", name: "name", newline: true, type: "text" , group: "用户信息", groupicon: 'groupicon'}, 
         { display: "性别", name: "sex", newline: false, type: "select" , options:{ data : [{text:'男',id:1},{text:'女',id:0}]}  },
         { display: "电子邮件", name: "email", newline: false, type: "text"  },
         { display: "电话号码", name: "phoneNumber", newline: false, validate:{ required: true, minlength: 11},  type: "text"  },
         { display: "年龄", name: "age", newline: false, type: "spinner",options:{ height: 22, type: 'int',isNegative:false }  },
         { display: "证件号", name: "idCardNo", newline: false, type: "text", validate:{ required: true, minlength: 18}  },
         {   display: "角色", name: "roleId", textField: "roleName",
             newline: false, type: "combobox", editor: { parms:[],
                 selectBoxWidth: 300,
                 selectBoxHeight: 300,
                 textField: 'name',
                 valeuField: 'id',
                 condition: {
                     fields: [
                         { label: '角色名称', name: 'name', type: 'text' ,width:100}
                     ]
                 },
                 grid: { columns: [
		                  { display: '角色名称', name: 'name', align: 'left', width: 120, minWidth: 100 },
		                  { display: '角色类型', name: 'type', width: 120, minWidth: 100 },
		                  { display: '主键', name: 'id', minWidth: 0, hide:true }],
		                  url:ctx + "/role/fetch.do",root:'datas', pageSize: 10, isScroll: false, sortName: 'name',
                     width: 240
                 }
             }},
             { display: "类型", name: "type", newline: false, type: "select", options:{ data : [{text:'内部用户',id:'1'},{text:'测试用户',id:'2'},{text:'外部用户',id:'0'}]}   }
         ],buttons:btns
		}); 
	
	loadModifyData();
	
	function loadModifyData(){
		if(id){
			 $.ajax({
		    		url: ctx+ '/usr/load.do',
		    		type : 'POST',
		    		dataType : 'json',
		    		data : {id:id},
		    		success : function(backData) {
		    			if(backData){
		    				$form.setData(backData);
		    			}
		    		}
		        });
		}
	}
	
});